package com.cdu.practicaltraining.sys.service.impl;

import com.cdu.practicaltraining.pojo.Role;
import com.cdu.practicaltraining.sys.mapper.RoleMapper;
import com.cdu.practicaltraining.sys.service.RoleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public int add(Role role) throws Exception {
        Role role1 = findByName(role.getRole_name());
        return null==role1 ? roleMapper.add(role) : -1;
    }

    @Override
    public Role findByName(String role_name) throws Exception {
        return roleMapper.findByName(role_name);
    }

    @Override
    public List<Role> roles() throws Exception {
        return roleMapper.roles();
    }

    @Override
    public Role findById(long id) throws Exception {
        return roleMapper.findById(id);
    }

    @Override
    public int updateRole(Role role) throws Exception {
        return roleMapper.updateRole(role);
    }

    @Override
    public int deleteRole(long id) throws Exception {
        return roleMapper.deleteRole(id);
    }
}
